package com.example.a14110100420.yuejian.WActivity.personal;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.a14110100420.yuejian.R;
import com.example.a14110100420.yuejian.WAdapter.personal.MyDingdanListAdapter;
import com.example.a14110100420.yuejian.WSerivice.PersonalService;
import com.example.a14110100420.yuejian.Wbase.BaseActivity;
import com.example.a14110100420.yuejian.Wbase.Conast;
import com.example.a14110100420.yuejian.Wbean.personal.MyOrder;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class DingdanDetailActivity extends BaseActivity {

    private RecyclerView recyclerView;
    private Retrofit retrofit;
    private MyDingdanListAdapter myDingdanListAdapter;
    private List<MyOrder> myOrders;
    final String userid = getUserid();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dingdan_detail);
        getSupportActionBar().hide();

        recyclerView = (RecyclerView) findViewById(R.id.user_dingdan_rec);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(DingdanDetailActivity.this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        init();

    }

    private void init(){
        String page="1";
        String SessionID="pf2cmg5jk9p24f2mv1kjf55bo3";
        retrofit = new Retrofit.Builder()
                .baseUrl(Conast.base_Url)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        PersonalService service = retrofit.create(PersonalService.class);
        Call<List<MyOrder>> call = service.getUserDingDan(userid,page,SessionID);
        call.enqueue(new Callback<List<MyOrder>>() {
            @Override
            public void onResponse(Call<List<MyOrder>> call, Response<List<MyOrder>> response) {
                List<MyOrder> list = response.body();
                MyDingdanListAdapter adapter = new MyDingdanListAdapter(DingdanDetailActivity.this,list);
                recyclerView.setAdapter(adapter);

            }

            @Override
            public void onFailure(Call<List<MyOrder>> call, Throwable t) {
                Toast.makeText(DingdanDetailActivity.this,"获取列表失败",Toast.LENGTH_LONG).show();

            }
        });
    }
}
